﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GetCar
{
    class ConcreteCarFactory : CarFactory
    {
        private static ConcreteCarFactory instance;
        private ConcreteCarFactory() { }
        private CarPool CarShop = new CarPool();

        //ConcreteCarFactory is Singleton
        public static ConcreteCarFactory GetCarFactory
        {
            get
            {
                if (instance == null)
                    instance = new ConcreteCarFactory();

                return instance;
            }
        }

        //The function for ordering a car
        public override Car CommandCar(String CarType, String Colour, String Transmission, String Moto)
        { 
            //car type: Mini 1 Sedan 2 Coupe 3
            Car NewCar;

            switch (CarType)
                {
                    case "mini": //if a Mini Car is requested
                        NewCar = CarShop.GetMini(Colour, Transmission, Moto);
                        return NewCar;
                    case "sedan": //if a Sedan Car is requested
                        NewCar = CarShop.GetSedan(Colour, Transmission, Moto);
                        return NewCar;
                    case "coupe": //if a Coupe Car is requested
                        NewCar = CarShop.GetCoupe(Colour, Transmission, Moto);
                        return NewCar;
                }

            return null;
        }

        //The function for putting a car back into the pool once it is returned by client
        public override void PutCarBack(Car TheCar)
        {
            String CarType = TheCar.GetCarType();

            switch (CarType)
            {
                case "Mini":
                    CarShop.PutMiniBack((Mini)TheCar);
                    break;
                case "Sedan":
                    CarShop.PutSedanBack((Sedan)TheCar);
                    break;
                case "Coupe":
                    CarShop.PutCoupeBack((Coupe)TheCar);
                    break;
            }
        }
    }
}
